﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Configuration;
using Constants = FlorDeLiz.Utils.Constants;
using System.Data;
using FlorDeLiz.LogException;
using FlorDeLiz.BusinessEntitites;
using System.Reflection;



namespace FlorDeLiz.DataAccess
{
    public abstract class BaseDA
    {
        private static MySqlConnection conexao;
        public static MySqlConnection Conexao
        {
            get
            {
                if (conexao == null)
                {
                    conexao = new MySqlConnection(Properties.Settings.Default.connectionString);
                }
                return conexao;
            }
        }

        public static MySqlCommand CommandSql = new MySqlCommand();

        public static MySqlParameter AdicionarParametro(string paramName, MySqlDbType paramType, int size, ParameterDirection direction, object value)
        {
            MySqlParameter parametro = null;
            try
            {
                parametro = new MySqlParameter(paramName, paramType, size);
                parametro.Direction = direction;
                parametro.Value = value;
            }
            catch(Exception ex)
            {
                parametro = null;
                LogService.GravarLog(Log.Instancia.Loggin(DateTime.Now,
                                                           ex.Message,
                                                           MethodBase.GetCurrentMethod().DeclaringType.Name,
                                                           MethodBase.GetCurrentMethod().Name,
                                                           ex.StackTrace));
            }

            return parametro;
        }               
    }
}
